home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / answers / comp / compression-faq / part2 < prev    next >
Internet Message Format  |  1994-04-17  |  88KB

  1. Path: bloom-beacon.mit.edu!news.kei.com!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!julienas!chorus!chorus.fr
  2. From: jloup@chorus.fr (Jean-loup Gailly)
  3. Newsgroups: comp.compression,comp.compression.research,news.answers,comp.answers
  4. Subject: comp.compression Frequently Asked Questions (part 2/3)
  5. Summary: *** READ THIS BEFORE POSTING ***
  6. Keywords: data compression, FAQ
  7. Message-ID: <compr2_17apr94@chorus.fr>
  8. Date: 17 Apr 94 12:28:51 GMT
  9. Expires: 30 May 94 16:17:20 GMT
  10. References: <compr1_17apr94@chorus.fr>
  11. Sender: news@chorus.chorus.fr
  12. Reply-To: jloup@chorus.fr
  13. Followup-To: comp.compression
  14. Lines: 1764
  15. Approved: news-answers-request@MIT.Edu
  16. Supersedes: <compr2_18mar94@chorus.fr>
  17. Xref: bloom-beacon.mit.edu comp.compression:7403 comp.compression.research:1153 news.answers:18172 comp.answers:4938
  18.  
  19. Archive-name: compression-faq/part2
  20. Last-modified: April 17th, 1994
  21.  
  22. This file is part 2 of a set of Frequently Asked Questions for the
  23. groups comp.compression and comp.compression.research.
  24. If you did not get part 1 or 3, you can get them by ftp
  25. on rtfm.mit.edu in directory
  26.    /pub/usenet/news.answers/compression-faq
  27.  
  28. If you don't want to see this FAQ regularly, please add the subject
  29. line to your kill file. If you have corrections or suggestions for
  30. this FAQ, send them to Jean-loup Gailly <jloup@chorus.fr>.  Thank you.
  31.  
  32. Contents
  33. ========
  34.  
  35. Part 2: (Long) introductions to data compression techniques
  36.  
  37. [70] Introduction to data compression (long)
  38.        Huffman and Related Compression Techniques
  39.        Arithmetic Coding
  40.        Substitutional Compressors
  41.           The LZ78 family of compressors
  42.           The LZ77 family of compressors
  43.  
  44. [71] Introduction to MPEG (long)
  45.        What is MPEG?
  46.        Does it have anything to do with JPEG?
  47.        Then what's JBIG and MHEG?
  48.        What has MPEG accomplished?
  49.        So how does MPEG I work?
  50.        What about the audio compression?
  51.        So how much does it compress?
  52.        What's phase II?
  53.        When will all this be finished?
  54.        How do I join MPEG?
  55.        How do I get the documents, like the MPEG I draft?
  56.  
  57. [72] What is wavelet theory?
  58. [73] What is the theoretical compression limit?
  59. [74] Introduction to JBIG
  60. [75] Introduction to JPEG
  61. [76] What is Vector Quantization?
  62. [77] Introduction to Fractal compression
  63.  
  64. Part 3: (Long) list of image compression hardware
  65.  
  66. [85] Image compression hardware
  67. [99] Acknowledgments
  68.  
  69.  
  70. Search for "Subject: [#]" to get to question number # quickly. Some news
  71. readers can also take advantage of the message digest format used here.
  72.  
  73. ------------------------------------------------------------------------------
  74.  
  75. Subject: [70] Introduction to data compression (long)
  76.  
  77.  
  78. Written by Peter Gutmann <pgut1@cs.aukuni.ac.nz>.
  79.  
  80.  Huffman and Related Compression Techniques
  81.  ------------------------------------------
  82.  
  83.   *Huffman compression* is a statistical data compression technique which 
  84. gives a reduction in the average code length used to represent the symbols of 
  85. a alphabet.  The Huffman code is an example of a code which is optimal in the 
  86. case where all symbols probabilities are integral powers of 1/2.  A Huffman 
  87. code can be built in the following manner:
  88.  
  89.   (1) Rank all symbols in order of probability of occurrence.
  90.     
  91.   (2) Successively combine the two symbols of the lowest probability to form
  92.       a new composite symbol; eventually we will build a binary tree where
  93.       each node is the probability of all nodes beneath it.
  94.  
  95.   (3) Trace a path to each leaf, noticing the direction at each node.
  96.  
  97.   For a given frequency distribution, there are many possible Huffman codes,
  98. but the total compressed length will be the same. It is possible to
  99. define a 'canonical' Huffman tree, that is, pick one of these alternative
  100. trees. Such a canonical tree can then be represented very compactly, by
  101. transmitting only the bit length of each code. This technique is used
  102. in most archivers (pkzip, lha, zoo, arj, ...).
  103.  
  104.  
  105.   A technique related to Huffman coding is *Shannon-Fano coding*, which
  106. works as follows:
  107.  
  108.   (1) Divide the set of symbols into two equal or almost equal subsets
  109.       based on the probability of occurrence of characters in each
  110.       subset.  The first subset is assigned a binary zero, the second
  111.       a binary one.
  112.  
  113.   (2) Repeat step (1) until all subsets have a single element.
  114.  
  115. The algorithm used to create the Huffman codes is bottom-up, and the
  116. one for the Shannon-Fano codes is top-down. Huffman encoding always
  117. generates optimal codes, Shannon-Fano sometimes uses a few more bits.
  118.  
  119.  
  120.  Arithmetic Coding
  121.  -----------------
  122.  
  123.   It would appear that Huffman or Shannon-Fano coding is the perfect
  124. means of compressing data.  However, this is *not* the case.  As
  125. mentioned above, these coding methods are optimal when and only when
  126. the symbol probabilities are integral powers of 1/2, which is usually
  127. not the case.
  128.  
  129.   The technique of *arithmetic coding* does not have this restriction:
  130. It achieves the same effect as treating the message as one single unit
  131. (a technique which would, for Huffman coding, require enumeration of
  132. every single possible message), and thus attains the theoretical
  133. entropy bound to compression efficiency for any source.
  134.  
  135.   Arithmetic coding works by representing a number by an interval of real 
  136. numbers between 0 and 1.  As the message becomes longer, the interval needed 
  137. to represent it becomes smaller and smaller, and the number of bits needed to 
  138. specify that interval increases.  Successive symbols in the message reduce 
  139. this interval in accordance with the probability of that symbol. The more
  140. likely symbols reduce the range by less, and thus add fewer bits to the   
  141. message.
  142.  
  143.      1                                             Codewords
  144.     +-----------+-----------+-----------+           /-----\
  145.     |           |8/9 YY     |  Detail   |<- 31/32    .11111
  146.     |           +-----------+-----------+<- 15/16    .1111
  147.     |    Y      |           | too small |<- 14/16    .1110
  148.     |2/3        |    YX     | for text  |<- 6/8      .110
  149.     +-----------+-----------+-----------+
  150.     |           |           |16/27 XYY  |<- 10/16    .1010
  151.     |           |           +-----------+
  152.     |           |    XY     |           |
  153.     |           |           |   XYX     |<- 4/8      .100
  154.     |           |4/9        |           |
  155.     |           +-----------+-----------+
  156.     |           |           |           |
  157.     |    X      |           |   XXY     |<- 3/8      .011
  158.     |           |           |8/27       |
  159.     |           |           +-----------+
  160.     |           |    XX     |           |
  161.     |           |           |           |<- 1/4      .01
  162.     |           |           |   XXX     |
  163.     |           |           |           |
  164.     |0          |           |           |
  165.     +-----------+-----------+-----------+
  166.  
  167.   As an example of arithmetic coding, lets consider the example of two
  168. symbols X and Y, of probabilities 0.66 and 0.33. To encode this message, we
  169. examine the first symbol: If it is a X, we choose the lower partition; if
  170. it is a Y, we choose the upper partition.  Continuing in this manner for
  171. three symbols, we get the codewords shown to the right of the diagram above
  172. - they can be found by simply taking an appropriate location in the
  173. interval for that particular set of symbols and turning it into a binary
  174. fraction. In practice, it is also necessary to add a special end-of-data
  175. symbol, which is not represented in this simpe example.
  176.         
  177.   In this case the arithmetic code is not completely efficient, which is due 
  178. to the shortness of the message - with longer messages the coding efficiency 
  179. does indeed approach 100%.
  180.  
  181.   Now that we have an efficient encoding technique, what can we do with it? 
  182. What we need is a technique for building a model of the data which we can 
  183. then use with the encoder.  The simplest model is a fixed one, for example a 
  184. table of standard letter frequencies for English text which we can then use 
  185. to get letter probabilities.  An improvement on this technique is to use an 
  186. *adaptive model*, in other words a model which adjusts itself to the data 
  187. which is being compressed as the data is compressed.  We can convert the 
  188. fixed model into an adaptive one by adjusting the symbol frequencies after 
  189. each new symbol is encoded, allowing the model to track the data being 
  190. transmitted.  However, we can do much better than that.
  191.  
  192. Using the symbol probabilities by themselves is not a particularly good
  193. estimate of the true entropy of the data: We can take into account
  194. intersymbol probabilities as well.  The best compressors available today
  195. take this approach: DMC (Dynamic Markov Coding) starts with a zero-order
  196. Markov model and gradually extends this initial model as compression
  197. progresses; PPM (Prediction by Partial Matching) looks for a match of the
  198. text to be compressed in an order-n context.  If no match is found, it
  199. drops to an order n-1 context, until it reaches order 0.  Both these
  200. techniques thus obtain a much better model of the data to be compressed,
  201. which, combined with the use of arithmetic coding, results in superior
  202. compression performance.
  203.  
  204.   So if arithmetic coding-based compressors are so powerful, why are they not 
  205. used universally?  Apart from the fact that they are relatively new and 
  206. haven't come into general use too much yet, there is also one major concern:  
  207. The fact that they consume rather large amounts of computing resources, both 
  208. in terms of CPU power and memory.  The building of sophisticated models for 
  209. the compression can chew through a fair amount of memory (especially in the 
  210. case of DMC, where the model can grow without bounds); and the arithmetic 
  211. coding itself involves a fair amount of number crunching.
  212. There is however an alternative approach, a class of compressors generally 
  213. referred to as *substitutional* or *dictionary-based compressors*.
  214.  
  215.  Substitutional Compressors
  216.  --------------------------
  217.  
  218.   The basic idea behind a substitutional compressor is to replace an 
  219. occurrence of a particular phrase or group of bytes in a piece of data with a 
  220. reference to a previous occurrence of that phrase.  There are two main 
  221. classes of schemes, named after Jakob Ziv and Abraham Lempel, who first 
  222. proposed them in 1977 and 1978.
  223.  
  224. <The LZ78 family of compressors>
  225.  
  226.   LZ78-based schemes work by entering phrases into a *dictionary* and then, 
  227. when a repeat occurrence of that particular phrase is found, outputting the 
  228. dictionary index instead of the phrase.  There exist several compression 
  229. algorithms based on this principle, differing mainly in the manner in which 
  230. they manage the dictionary.  The most well-known scheme (in fact the most 
  231. well-known of all the Lempel-Ziv compressors, the one which is generally (and 
  232. mistakenly) referred to as "Lempel-Ziv Compression"), is Terry Welch's LZW 
  233. scheme, which he designed in 1984 for implementation in hardware for high- 
  234. performance disk controllers.
  235.  
  236. Input string: /WED/WE/WEE/WEB
  237.  
  238. Character input:    Code output:    New code value and associated string:
  239.     /W                  /                   256 = /W
  240.     E                   W                   257 = WE
  241.     D                   E                   258 = ED
  242.     /                   D                   259 = D/
  243.     WE                  256                 260 = /WE
  244.     /                   E                   261 = E/
  245.     WEE                 260                 262 = /WEE
  246.     /W                  261                 263 = E/W
  247.     EB                  257                 264 = WEB
  248.     <END>               B
  249.     
  250.   LZW starts with a 4K dictionary, of which entries 0-255 refer to individual 
  251. bytes, and entries 256-4095 refer to substrings.  Each time a new code is 
  252. generated it means a new string has been parsed.  New strings are generated 
  253. by appending the current character K to the end of an existing string w.  The 
  254. algorithm for LZW compression is as follows:
  255.  
  256.   set w = NIL
  257.   loop
  258.       read a character K
  259.       if wK exists is in the dictionary
  260.           w = wK
  261.       else
  262.           output the code for w
  263.           add wK to the string table
  264.           w = K
  265.   endloop
  266.  
  267.   A sample run of LZW over a (highly redundant) input string can be seen in 
  268. the diagram above.  The strings are built up character-by-character starting 
  269. with a code value of 256.  LZW decompression takes the stream of codes and 
  270. uses it to exactly recreate the original input data.  Just like the 
  271. compression algorithm, the decompressor adds a new string to the dictionary 
  272. each time it reads in a new code.  All it needs to do in addition is to 
  273. translate each incoming code into a string and send it to the output.  A 
  274. sample run of the LZW decompressor is shown in below.
  275.  
  276. Input code: /WED<256>E<260><261><257>B
  277.  
  278. Input code:        Output string:     New code value and associated string:
  279.     /                  /            
  280.     W                  W                      256 = /W
  281.     E                  E                      257 = WE
  282.     D                  D                      258 = ED
  283.     256                /W                     259 = D/
  284.     E                  E                      260 = /WE
  285.     260                /WE                    261 = E/
  286.     261                E/                     262 = /WEE
  287.     257                WE                     263 = E/W
  288.     B                  B                      264 = WEB
  289.            
  290.   The most remarkable feature of this type of compression is that the entire 
  291. dictionary has been transmitted to the decoder without actually explicitly 
  292. transmitting the dictionary.  At the end of the run, the decoder will have a 
  293. dictionary identical to the one the encoder has, built up entirely as part of 
  294. the decoding process.
  295.     LZW is more commonly encountered today in a variant known as LZC, after 
  296. its use in the UNIX "compress" program.  In this variant, pointers do not 
  297. have a fixed length.  Rather, they start with a length of 9 bits, and then 
  298. slowly grow to their maximum possible length once all the pointers of a 
  299. particular size have been used up.  Furthermore, the dictionary is not frozen 
  300. once it is full as for LZW - the program continually monitors compression 
  301. performance, and once this starts decreasing the entire dictionary is 
  302. discarded and rebuilt from scratch.  More recent schemes use some sort of 
  303. least-recently-used algorithm to discard little-used phrases once the 
  304. dictionary becomes full rather than throwing away the entire dictionary.  
  305.  
  306. Finally, not all schemes build up the dictionary by adding a single new 
  307. character to the end of the current phrase. An alternative technique is to 
  308. concatenate the previous two phrases (LZMW), which results in a faster 
  309. buildup of longer phrases than the character-by-character buildup of the 
  310. other methods.  The disadvantage of this method is that a more sophisticated 
  311. data structure is needed to handle the dictionary.
  312.  
  313. [A good introduction to LZW, MW, AP and Y coding is given in the yabba
  314. package. For ftp information, see question 2 in part one, file type .Y]
  315.  
  316.  
  317. <The LZ77 family of compressors>
  318.  
  319.   LZ77-based schemes keep track of the last n bytes of data seen, and when a 
  320. phrase is encountered that has already been seen, they output a pair of 
  321. values corresponding to the position of the phrase in the previously-seen 
  322. buffer of data, and the length of the phrase.  In effect the compressor moves 
  323. a fixed-size *window* over the data (generally referred to as a *sliding 
  324. window*), with the position part of the (position, length) pair referring to 
  325. the position of the phrase within the window.  The most commonly used 
  326. algorithms are derived from the LZSS scheme described by James Storer and 
  327. Thomas Szymanski in 1982.  In this the compressor maintains a window of size 
  328. N bytes and a *lookahead buffer* the contents of which it tries to find a 
  329. match for in the window:
  330.  
  331.   while( lookAheadBuffer not empty )
  332.       {
  333.       get a pointer ( position, match ) to the longest match in the window
  334.           for the lookahead buffer;
  335.  
  336.       if( length > MINIMUM_MATCH_LENGTH )
  337.           {
  338.           output a ( position, length ) pair;
  339.           shift the window length characters along;
  340.           }
  341.       else
  342.           {
  343.           output the first character in the lookahead buffer;
  344.           shift the window 1 character along;
  345.           }
  346.       }
  347.         
  348.   Decompression is simple and fast:  Whenever a ( position, length ) pair is 
  349. encountered, go to that ( position ) in the window and copy ( length ) bytes 
  350. to the output.
  351.  
  352.   Sliding-window-based schemes can be simplified by numbering the input text
  353. characters mod N, in effect creating a circular buffer.  The sliding window
  354. approach automatically creates the LRU effect which must be done explicitly in
  355. LZ78 schemes.  Variants of this method apply additional compression to the
  356. output of the LZSS compressor, which include a simple variable-length code
  357. (LZB), dynamic Huffman coding (LZH), and Shannon-Fano coding (ZIP 1.x)), all
  358. of which result in a certain degree of improvement over the basic scheme,
  359. especially when the data are rather random and the LZSS compressor has little
  360. effect.
  361.   Recently an algorithm was developed which combines the ideas behind LZ77 and
  362. LZ78 to produce a hybrid called LZFG.  LZFG uses the standard sliding window,
  363. but stores the data in a modified trie data structure and produces as output
  364. the position of the text in the trie.  Since LZFG only inserts complete
  365. *phrases* into the dictionary, it should run faster than other LZ77-based
  366. compressors.
  367.  
  368. All popular archivers (arj, lha, zip, zoo) are variations on the LZ77 theme.
  369.  
  370. ------------------------------------------------------------------------------
  371.  
  372. Subject: [71] Introduction to MPEG (long)
  373.  
  374.  
  375. For MPEG players, see item 15 in part 1 of the FAQ.  Frank Gadegast
  376. <phade@cs.tu-berlin.de> also posts a FAQ specialized in MPEG, available in
  377. ftp.cs.tu-berlin.de:/pub/msdos/windows3/graphics/mpegfa*.zip.
  378. Chad Fogg <cfogg@ole.cdac.com> also has another FAQ in preparation.
  379. The site ftp.crs4.it dedicated to the MPEG compression standard,
  380. see the directory mpeg and subdirectories.
  381.  
  382.  
  383. Introduction to MPEG originally written by Mark Adler 
  384. <madler@cco.caltech.edu> around January 1992; modified and updated by 
  385. Harald Popp <layer3@iis.fhg.de> in March 94:
  386.  
  387. Q: What is MPEG, exactly?
  388.  
  389. A: MPEG is the "Moving Picture Experts Group", working under the 
  390.    joint direction of the International Standards Organization (ISO) 
  391.    and the International Electro-Technical Commission (IEC). This 
  392.    group works on standards for the coding of moving pictures and 
  393.    associated audio.
  394.  
  395. Q: What is the status of MPEG's work, then? What's about MPEG-1, -2, 
  396.    and so on?
  397.  
  398. A: MPEG approaches the growing need for multimedia standards step-by-
  399.    step. Today, three "phases" are defined:
  400.    
  401.    MPEG-1: "Coding of Moving Pictures and Associated Audio for 
  402.            Digital Storage Media at up to about 1.5 MBit/s"  
  403.  
  404.    Status: International Standard IS-11172, completed in 10.92
  405.    
  406.    MPEG-2: "Generic Coding of Moving Pictures and Associated Audio"
  407.    
  408.    Status: Comittee Draft CD 13818 as found in documents MPEG93 / 
  409.            N601, N602, N603 (11.93)   
  410.  
  411.    MPEG-3: does not longer exist (has been merged into MPEG-2)
  412.    
  413.    MPEG-4: "Very Low Bitrate Audio-Visual Coding"
  414.    
  415.    Status: Call for Proposals 11.94, Working Draft in 11.96 
  416.  
  417. Q: MPEG-1 is ready-for-use. How does the standard look like?
  418.  
  419. A: MPEG-1 consists of 4 parts:
  420.  
  421.    IS 11172-1: System
  422.    describes synchronization and multiplexing of video and audio
  423.  
  424.    IS 11172-2: Video
  425.    describes compression of non-interlaced video signals
  426.    
  427.    IS 11172-3: Audio
  428.    describes compression of audio signals 
  429.    
  430.    CD 11172-4: Compliance Testing
  431.    describes procedures for determining the characteristics of coded 
  432.    bitstreams and the decoding porcess and for testing compliance 
  433.    with the requirements stated in the other parts
  434.  
  435. Q. Does MPEG have anything to do with JPEG? 
  436.  
  437. A. Well, it sounds the same, and they are part of the same 
  438.    subcommittee of ISO along with JBIG and MHEG, and they usually meet 
  439.    at the same place at the same time.  However, they are different 
  440.    sets of people with few or no common individual members, and they 
  441.    have different charters and requirements.  JPEG is for still image 
  442.    compression.
  443.  
  444. Q. Then what's JBIG and MHEG?
  445.  
  446. A. Sorry I mentioned them. Ok, I'll simply say that JBIG is for binary
  447.    image compression (like faxes), and MHEG is for multi-media data
  448.    standards (like integrating stills, video, audio, text, etc.).
  449.    For an introduction to JBIG, see question 74 below.
  450.  
  451. Q. So how does MPEG-1 work? Tell me about video coding!
  452.  
  453. A. First off, it starts with a relatively low resolution video
  454.    sequence (possibly decimated from the original) of about 352 by
  455.    240 frames by 30 frames/s (US--different numbers for Europe),
  456.    but original high (CD) quality audio.  The images are in color,
  457.    but converted to YUV space, and the two chrominance channels
  458.    (U and V) are decimated further to 176 by 120 pixels.  It turns
  459.    out that you can get away with a lot less resolution in those
  460.    channels and not notice it, at least in "natural" (not computer
  461.    generated) images.
  462.  
  463.    The basic scheme is to predict motion from frame to frame in the
  464.    temporal direction, and then to use DCT's (discrete cosine
  465.    transforms) to organize the redundancy in the spatial directions.
  466.    The DCT's are done on 8x8 blocks, and the motion prediction is
  467.    done in the luminance (Y) channel on 16x16 blocks.  In other words,
  468.    given the 16x16 block in the current frame that you are trying to
  469.    code, you look for a close match to that block in a previous or
  470.    future frame (there are backward prediction modes where later
  471.    frames are sent first to allow interpolating between frames).
  472.    The DCT coefficients (of either the actual data, or the difference
  473.    between this block and the close match) are "quantized", which
  474.    means that you divide them by some value to drop bits off the
  475.    bottom end.  Hopefully, many of the coefficients will then end up
  476.    being zero.  The quantization can change for every "macroblock"
  477.    (a macroblock is 16x16 of Y and the corresponding 8x8's in both
  478.    U and V).  The results of all of this, which include the DCT
  479.    coefficients, the motion vectors, and the quantization parameters
  480.    (and other stuff) is Huffman coded using fixed tables.  The DCT
  481.    coefficients have a special Huffman table that is "two-dimensional"
  482.    in that one code specifies a run-length of zeros and the non-zero
  483.    value that ended the run.  Also, the motion vectors and the DC
  484.    DCT components are DPCM (subtracted from the last one) coded.
  485.  
  486. Q. So is each frame predicted from the last frame?
  487.  
  488. A. No.  The scheme is a little more complicated than that.  There are
  489.    three types of coded frames.  There are "I" or intra frames.  They
  490.    are simply a frame coded as a still image, not using any past
  491.    history.  You have to start somewhere.  Then there are "P" or
  492.    predicted frames.  They are predicted from the most recently
  493.    reconstructed I or P frame.  (I'm describing this from the point
  494.    of view of the decompressor.)  Each macroblock in a P frame can
  495.    either come with a vector and difference DCT coefficients for a
  496.    close match in the last I or P, or it can just be "intra" coded
  497.    (like in the I frames) if there was no good match.
  498.  
  499.    Lastly, there are "B" or bidirectional frames.  They are predicted
  500.    from the closest two I or P frames, one in the past and one in the
  501.    future.  You search for matching blocks in those frames, and try
  502.    three different things to see which works best.  (Now I have the
  503.    point of view of the compressor, just to confuse you.)  You try 
  504.    using the forward vector, the backward vector, and you try 
  505.    averaging the two blocks from the future and past frames, and 
  506.    subtracting that from the block being coded.  If none of those work 
  507.    well, you can intracode the block.
  508.  
  509.    The sequence of decoded frames usually goes like:
  510.  
  511.    IBBPBBPBBPBBIBBPBBPB...
  512.  
  513.    Where there are 12 frames from I to I (for US and Japan anyway.)
  514.    This is based on a random access requirement that you need a
  515.    starting point at least once every 0.4 seconds or so.  The ratio
  516.    of P's to B's is based on experience.
  517.  
  518.    Of course, for the decoder to work, you have to send that first
  519.    P *before* the first two B's, so the compressed data stream ends
  520.    up looking like:
  521.  
  522.    0xx312645...
  523.  
  524.    where those are frame numbers.  xx might be nothing (if this is
  525.    the true starting point), or it might be the B's of frames -2 and
  526.    -1 if we're in the middle of the stream somewhere.
  527.  
  528.    You have to decode the I, then decode the P, keep both of those
  529.    in memory, and then decode the two B's.  You probably display the
  530.    I while you're decoding the P, and display the B's as you're
  531.    decoding them, and then display the P as you're decoding the next
  532.    P, and so on.
  533.  
  534. Q. You've got to be kidding.
  535.  
  536. A. No, really!
  537.  
  538. Q. Hmm.  Where did they get 352x240?
  539.  
  540. A. That derives from the CCIR-601 digital television standard which
  541.    is used by professional digital video equipment.  It is (in the US)
  542.    720 by 243 by 60 fields (not frames) per second, where the fields
  543.    are interlaced when displayed.  (It is important to note though
  544.    that fields are actually acquired and displayed a 60th of a second
  545.    apart.)  The chrominance channels are 360 by 243 by 60 fields a
  546.    second, again interlaced.  This degree of chrominance decimation
  547.    (2:1 in the horizontal direction) is called 4:2:2.  The source
  548.    input format for MPEG I, called SIF, is CCIR-601 decimated by 2:1
  549.    in the horizontal direction, 2:1 in the time direction, and an
  550.    additional 2:1 in the chrominance vertical direction.  And some
  551.    lines are cut off to make sure things divide by 8 or 16 where
  552.    needed.
  553.  
  554. Q. What if I'm in Europe?
  555.  
  556. A. For 50 Hz display standards (PAL, SECAM) change the number of lines
  557.    in a field from 243 or 240 to 288, and change the display rate to
  558.    50 fields/s or 25 frames/s.  Similarly, change the 120 lines in
  559.    the decimated chrominance channels to 144 lines.  Since 288*50 is
  560.    exactly equal to 240*60, the two formats have the same source data
  561.    rate.
  562.  
  563. Q. What will MPEG-2 do for video coding?
  564.  
  565. A. As I said, there is a considerable loss of quality in going from
  566.    CCIR-601 to SIF resolution.  For entertainment video, it's simply
  567.    not acceptable.  You want to use more bits and code all or almost
  568.    all the CCIR-601 data.  From subjective testing at the Japan
  569.    meeting in November 1991, it seems that 4 MBits/s can give very
  570.    good quality compared to the original CCIR-601 material.  The
  571.    objective of MPEG-2 is to define a bit stream optimized for 
  572.    these resolutions and bit rates.
  573.  
  574. Q. Why not just scale up what you're doing with MPEG-1?
  575.  
  576. A. The main difficulty is the interlacing.  The simplest way to extend
  577.    MPEG-1 to interlaced material is to put the fields together into
  578.    frames (720x486x30/s).  This results in bad motion artifacts that
  579.    stem from the fact that moving objects are in different places
  580.    in the two fields, and so don't line up in the frames.  Compressing
  581.    and decompressing without taking that into account somehow tends to
  582.    muddle the objects in the two different fields.
  583.  
  584.    The other thing you might try is to code the even and odd field
  585.    streams separately.  This avoids the motion artifacts, but as you
  586.    might imagine, doesn't get very good compression since you are not
  587.    using the redundancy between the even and odd fields where there
  588.    is not much motion (which is typically most of image).
  589.  
  590.    Or you can code it as a single stream of fields.  Or you can
  591.    interpolate lines.  Or, etc. etc.  There are many things you can
  592.    try, and the point of MPEG-2 is to figure out what works well.
  593.    MPEG-2 is not limited to consider only derivations of MPEG-1.
  594.    There were several non-MPEG-1-like schemes in the competition in
  595.    November, and some aspects of those algorithms may or may not
  596.    make it into the final standard for entertainment video 
  597.    compression.
  598.  
  599. Q. So what works?
  600.  
  601. A. Basically, derivations of MPEG-1 worked quite well, with one that
  602.    used wavelet subband coding instead of DCT's that also worked very
  603.    well.  Also among the worked-very-well's was a scheme that did not
  604.    use B frames at all, just I and P's.  All of them, except maybe 
  605.    one, did some sort of adaptive frame/field coding, where a decision 
  606.    is made on a macroblock basis as to whether to code that one as 
  607.    one frame macroblock or as two field macroblocks.  Some other 
  608.    aspects are how to code I-frames--some suggest predicting the even 
  609.    field from the odd field.  Or you can predict evens from evens and 
  610.    odds or odds from evens and odds or any field from any other field, 
  611.    etc.
  612.  
  613. Q. So what works?
  614.  
  615. A. Ok, we're not really sure what works best yet.  The next step is
  616.    to define a "test model" to start from, that incorporates most of
  617.    the salient features of the worked-very-well proposals in a
  618.    simple way.  Then experiments will be done on that test model,
  619.    making a mod at a time, and seeing what makes it better and what
  620.    makes it worse.  Example experiments are, B's or no B's, DCT vs.
  621.    wavelets, various field prediction modes, etc.  The requirements,
  622.    such as implementation cost, quality, random access, etc. will all
  623.    feed into this process as well.
  624.  
  625. Q. When will all this be finished?
  626.  
  627. A. I don't know.  I'd have to hope in about a year or less.
  628.  
  629. Q: Talking about MPEG audio coding, I heard a lot about "Layer 1, 2 
  630.    and 3". What does it mean, exactly?   
  631.  
  632. A: MPEG-1, IS 11172-3, describes the compression of audio signals 
  633.    using high performance perceptual coding schemes. It specifies a 
  634.    family of three audio coding schemes, simply called Layer-1,-2,-3, 
  635.    with increasing encoder complexity and performance (sound quality 
  636.    per bitrate). The three codecs are compatible in a hierarchical 
  637.    way, i.e. a Layer-N decoder is able to decode bitstream data 
  638.    encoded in Layer-N and all Layers below N (e.g., a Layer-3 
  639.    decoder may accept Layer-1,-2 and -3, whereas a Layer-2 decoder 
  640.    may accept only Layer-1 and -2.)
  641.  
  642. Q: So we have a family of three audio coding schemes. What does the 
  643.    MPEG standard define, exactly?
  644.    
  645. A: For each Layer, the standard specifies the bitstream format and 
  646.    the decoder. To allow for future improvements, it does *not* 
  647.    specify the encoder , but an informative chapter gives an example 
  648.    for an encoder for each Layer.    
  649.  
  650. Q: What have the three audio Layers in common?
  651.  
  652. A: All Layers use the same basic structure. The coding scheme can be  
  653.    described as "perceptual noise shaping" or "perceptual subband / 
  654.    transform coding". 
  655.  
  656.    The encoder analyzes the spectral components of the audio signal 
  657.    by calculating a filterbank or transform and applies a 
  658.    psychoacoustic model to estimate the just noticeable noise-
  659.    level. In its quantization and coding stage, the encoder tries 
  660.    to allocate the available number of data bits in a way to meet 
  661.    both the bitrate and masking requirements.
  662.  
  663.    The decoder is much less complex. Its only task is to synthesize 
  664.    an audio signal out of the coded spectral components.
  665.    
  666.    All Layers use the same analysis filterbank (polyphase with 32 
  667.    subbands). Layer-3 adds a MDCT transform to increase the frequency 
  668.    resolution.
  669.    
  670.    All Layers use the same "header information" in their bitstream, 
  671.    to support the hierarchical structure of the standard.
  672.    
  673.    All Layers use a bitstream structure that contains parts that are 
  674.    more sensitive to biterrors ("header", "bit allocation", 
  675.    "scalefactors", "side information") and parts that are less 
  676.    sensitive ("data of spectral components").  
  677.  
  678.    All Layers may use 32, 44.1 or 48 kHz sampling frequency.
  679.    
  680.    All Layers are allowed to work with similar bitrates:
  681.    Layer-1: from 32 kbps to 448 kbps
  682.    Layer-2: from 32 kbps to 384 kbps
  683.    Layer-3: from 32 kbps to 320 kbps
  684.  
  685. Q: What are the main differences between the three Layers, from a 
  686.    global view?
  687.  
  688. A: From Layer-1 to Layer-3,
  689.    complexity increases (mainly true for the encoder),
  690.    overall codec delay increases, and
  691.    performance increases (sound quality per bitrate).
  692.  
  693. Q: Which Layer should I use for my application?
  694.  
  695. A: Good Question. Of course, it depends on all your requirements. But 
  696.    as a first approach, you should consider the available bitrate of 
  697.    your application as the Layers have been designed to support 
  698.    certain areas of bitrates most efficiently, i.e. with a minimum 
  699.    drop of sound quality.
  700.  
  701.    Let us look a little closer at the strong domains of each Layer.
  702.     
  703.    Layer-1: Its ISO target bitrate is 192 kbps per audio channel.
  704.  
  705.    Layer-1 is a simplified version of Layer-2. It is most useful for 
  706.    bitrates around the "high" bitrates around or above 192 kbps. A 
  707.    version of Layer-1 is used as "PASC" with the DCC recorder.
  708.  
  709.    Layer-2: Its ISO target bitrate is 128 kbps per audio channel.
  710.    
  711.    Layer-2 is identical with MUSICAM. It has been designed as trade-
  712.    off between sound quality per bitrate and encoder complexity. It 
  713.    is most useful for bitrates around the "medium" bitrates of 128 or 
  714.    even 96 kbps per audio channel. The DAB (EU 147) proponents have 
  715.    decided to use Layer-2 in the future Digital Audio Broadcasting 
  716.    network.      
  717.  
  718.    Layer-3: Its ISO target bitrate is 64 kbps per audio channel.
  719.    
  720.    Layer-3 merges the best ideas of MUSICAM and ASPEC. It has been 
  721.    designed for best performance at "low" bitrates around 64 kbps or 
  722.    even below. The Layer-3 format specifies a set of advanced 
  723.    features that all address one goal: to preserve as much sound 
  724.    quality as possible even at rather low bitrates. Today, Layer-3 is 
  725.    already in use in various telecommunication networks (ISDN, 
  726.    satellite links, and so on) and speech announcement systems. 
  727.  
  728. Q: Tell me more about sound quality. How do you assess that?
  729.  
  730. A: Today, there is no alternative to expensive listening tests. 
  731.    During the ISO-MPEG-1 process, 3 international listening tests 
  732.    have been performed, with a lot of trained listeners, supervised 
  733.    by Swedish Radio. They took place in 7.90, 3.91 and 11.91. Another 
  734.    international listening test was performed by CCIR, now ITU-R, in 
  735.    92.      
  736.    
  737.    All these tests used the "triple stimulus, hidden reference" 
  738.    method and the CCIR impairment scale to assess the audio quality.
  739.    The listening sequence is "ABC", with A = original, BC = pair of 
  740.    original / coded signal with random sequence, and the listener has 
  741.    to evaluate both B and C with a number between 1.0 and 5.0. The 
  742.    meaning of these values is:
  743.    
  744.    5.0 = transparent (this should be the original signal)
  745.    4.0 = perceptible, but not annoying (first differences noticable)  
  746.    3.0 = slightly annoying   
  747.    2.0 = annoying
  748.    1.0 = very annoying
  749.  
  750.    With perceptual codecs (like MPEG audio), all traditional 
  751.    parameters (like SNR, THD+N, bandwidth) are especially useless. 
  752.    Fraunhofer-IIS works on objective quality assessment tools, like 
  753.    the NMR meter (Noise-to-Mask-Ratio), too. BTW: If you need more 
  754.    informations about NMR, please contact nmr@iis.fhg.de.
  755.  
  756. Q: Now that I know how to assess quality, come on, tell me the 
  757.    results of these tests.
  758.    
  759. A: Well, for low bitrates, the main result is that at 60 or 64 kbps 
  760.    per channel), Layer-2 scored always between 2.1 and 2.6, whereas 
  761.    Layer-3 scored between 3.6 and 3.8. This is a significant increase 
  762.    in sound quality, indeed! Furthermore, the selection process for 
  763.    critical sound material showed that it was rather difficult to 
  764.    find worst-case material for Layer-3 whereas it was not so hard to 
  765.    find such items for Layer-2.
  766.   
  767. Q: OK, a Layer-2 codec at low bitrates may sound poor today, but 
  768.    couldn't that be improved in the future? I guess you just told me 
  769.    before that the encoder is not fixed in the standard.
  770.    
  771. A: Good thinking! As the sound quality mainly depends on the encoder 
  772.    implementation, it is true that there is no such thing as a "Layer-
  773.    N"- quality. So we definitely only know the performance of the 
  774.    reference codecs during the international tests. Who knows what 
  775.    will happen in the future? What we do know now, is:
  776.    
  777.    Today, Layer-3 already provides a sound quality that comes very 
  778.    near to CD quality at 64 kbps per channel. Layer-2 is far away 
  779.    from that.
  780.    
  781.    Tomorrow, both Layers may improve. Layer-2 has been designed as a 
  782.    trade-off between quality and complexity, so the bitstream format 
  783.    allows only limited innovations. In contrast, even the current
  784.    reference Layer-3-codec exploits only a small part of the powerful 
  785.    mechanisms inside the Layer-3 bitstream format.  
  786.  
  787. Q: All in all, you sound as if anybody should use Layer-3 for low 
  788.    bitrates. Why on earth do some vendors still offer only Layer-2 
  789.    equipment for these applications?
  790.    
  791. A: Well, maybe because they started to design and develop their 
  792.    system rather early, e.g. in 1990. As Layer-2 is identical with 
  793.    MUSICAM, it has been available since summer of 90, at latest. In 
  794.    that year, Layer-3 development started and could be successfully 
  795.    finished in spring 92. So, for a certain time, vendors could only 
  796.    exploit the existing part of the new MPEG standard.   
  797.    
  798.    Now the situation has changed. All Layers are available, the 
  799.    standard is completed, and new systems need not limit themselves, 
  800.    but may capitalize on the full features of MPEG audio.
  801.  
  802. Q: How do I get the MPEG documents?
  803.  
  804. A: You may order it from your national standards body.
  805.  
  806.    E.g., in Germany, please contact:
  807.    DIN-Beuth Verlag, Auslandsnormen
  808.    Mrs. Niehoff, Burggrafenstr. 6, D-10772 Berlin, Germany
  809.    Phone: 030-2601-2757, Fax: 030-2601-1231
  810.  
  811.    E.g., in USA, you may order it from ANSI or 
  812.    buy it from companies like OMNICOM phone +44 438 742424
  813.                                       FAX   +44 438 740154
  814.  
  815. Q. How do I join MPEG?
  816.  
  817. A. You don't join MPEG.  You have to participate in ISO as part of a
  818.    national delegation.  How you get to be part of the national
  819.    delegation is up to each nation.  I only know the U.S., where you
  820.    have to attend the corresponding ANSI meetings to be able to
  821.    attend the ISO meetings.  Your company or institution has to be
  822.    willing to sink some bucks into travel since, naturally, these
  823.    meetings are held all over the world.  (For example, Paris,
  824.    Santa Clara, Kurihama Japan, Singapore, Haifa Israel, Rio de
  825.    Janeiro, London, etc.)
  826.  
  827. ------------------------------------------------------------------------------
  828.  
  829. Subject: [72] What is wavelet theory?
  830.  
  831.  
  832. Preprints and software are available by anonymous ftp from the
  833. Yale Mathematics Department computer ceres.math.yale.edu[130.132.23.22],
  834. in pub/wavelets and pub/software.
  835.  
  836. epic and hcompress are wavelet coders. (For source code, see item 15
  837. in part one).
  838.  
  839. Bill Press of Harvard/CfA has made some things available for anonymous
  840. ftp on cfata4.harvard.edu [128.103.40.79] in directory /pub. There is
  841. a short TeX article on wavelet theory (wavelet.tex, to be included in
  842. a future edition of Numerical Recipes), some sample wavelet code
  843. (wavelet.f, in FORTRAN - sigh), and a beta version of an astronomical
  844. image compression program which he is currently developing (FITS
  845. format data files only, in fitspress08.tar.Z).
  846.  
  847. The Rice Wavelet Toolbox Release 2.0 is available on cml.rice.edu in
  848. directories /pub/dsp/software and /pub/dsp/papers.  This is a
  849. collection of MATLAB of "mfiles" and "mex" files for twoband and
  850. M-band filter bank/wavelet analysis from the DSP group and
  851. Computational Mathematics Laboratory (CML) at Rice University,
  852. Houston, TX.  This release includes application code for Synthetic
  853. Aperture Radar despeckling and for deblocking of JPEG decompressed
  854. Images.  Contact: Ramesh Gopinath <ramesh@rice.edu>.
  855.  
  856.  
  857. A mailing list dedicated to research on wavelets has been set up at the
  858. University of South Carolina. To subscribe to this mailing list, send a
  859. message with "subscribe" as the subject to wavelet@math.scarolina.edu.
  860.  
  861.  
  862. A 5 minute course in wavelet transforms, by Richard Kirk <rak@crosfield.co.uk>:
  863.  
  864. Do you know what a Haar transform is? Its a transform to another orthonormal
  865. space (like the DFT), but the basis functions are a set of square wave bursts
  866. like this...
  867.  
  868.    +--+                         +------+
  869.    +  |  +------------------    +      |      +--------------
  870.       +--+                             +------+
  871.  
  872.          +--+                                 +------+
  873.    ------+  |  +------------    --------------+      |      +
  874.             +--+                                     +------+
  875.  
  876.                +--+             +-------------+
  877.    ------------+  |  +------    +             |             +
  878.                   +--+                        +-------------+
  879.  
  880.                      +--+       +---------------------------+
  881.    ------------------+  |  +    +                           +
  882.                         +--+
  883.  
  884. This is the set of functions for an 8-element 1-D Haar transform. You
  885. can probably see how to extend this to higher orders and higher dimensions
  886. yourself. This is dead easy to calculate, but it is not what is usually
  887. understood by a wavelet transform.
  888.  
  889. If you look at the eight Haar functions you see we have four functions
  890. that code the highest resolution detail, two functions that code the
  891. coarser detail, one function that codes the coarser detail still, and the 
  892. top function that codes the average value for the whole `image'.
  893.  
  894. Haar function can be used to code images instead of the DFT. With bilevel
  895. images (such as text) the result can look better, and it is quicker to code.
  896. Flattish regions, textures, and soft edges in scanned images get a nasty
  897. `blocking' feel to them. This is obvious on hardcopy, but can be disguised on
  898. color CRTs by the effects of the shadow mask. The DCT gives more consistent
  899. results.
  900.  
  901. This connects up with another bit of maths sometimes called Multispectral
  902. Image Analysis, sometimes called Image Pyramids.
  903.  
  904. Suppose you want to produce a discretely sampled image from a continuous 
  905. function. You would do this by effectively `scanning' the function using a
  906. sinc function [ sin(x)/x ] `aperture'. This was proved by Shannon in the 
  907. `forties. You can do the same thing starting with a high resolution
  908. discretely sampled image. You can then get a whole set of images showing 
  909. the edges at different resolutions by differencing the image at one
  910. resolution with another version at another resolution. If you have made this
  911. set of images properly they ought to all add together to give the original 
  912. image.
  913.  
  914. This is an expansion of data. Suppose you started off with a 1K*1K image.
  915. You now may have a 64*64 low resolution image plus difference images at 128*128
  916. 256*256, 512*512 and 1K*1K. 
  917.  
  918. Where has this extra data come from? If you look at the difference images you 
  919. will see there is obviously some redundancy as most of the values are near 
  920. zero. From the way we constructed the levels we know that locally the average
  921. must approach zero in all levels but the top. We could then construct a set of
  922. functions out of the sync functions at any level so that their total value 
  923. at all higher levels is zero. This gives us an orthonormal set of basis 
  924. functions for a transform. The transform resembles the Haar transform a bit,
  925. but has symmetric wave pulses that decay away continuously in either direction
  926. rather than square waves that cut off sharply. This transform is the
  927. wavelet transform ( got to the point at last!! ).
  928.  
  929. These wavelet functions have been likened to the edge detecting functions
  930. believed to be present in the human retina.
  931.  
  932.  
  933. Loren I. Petrich <lip@s1.gov> adds that order 2 or 3 Daubechies
  934. discrete wavelet transforms have a speed comparable to DCT's, and
  935. usually achieve compression a factor of 2 better for the same image
  936. quality than the JPEG 8*8 DCT. (See item 25 in part 1 of this FAQ for
  937. references on fast DCT algorithms.)
  938.  
  939. ------------------------------------------------------------------------------
  940.  
  941. Subject: [73] What is the theoretical compression limit?
  942.  
  943.  
  944. There is no compressor that is guaranteed to compress all possible input
  945. files. If it compresses some files, then it must enlarge some others.
  946. This can be proven by a simple counting argument (see question 9).
  947.  
  948. As an extreme example, the following algorithm achieves optimal
  949. compression for one special input file and enlarges all other files by
  950. only one bit:
  951.  
  952. - if the input data is <insert your favorite one here>, output a single 0 bit
  953. - otherwise output the bit 1 followed by the input data.
  954.  
  955. (You can even output an empty file in the first case if the decompressor
  956. can detect by other means that the input is empty.)
  957.  
  958. The concept of theoretical compression limit is meaningful only
  959. if you have a model for your input data. See question 70 above
  960. for some examples of data models.
  961.  
  962. ------------------------------------------------------------------------------
  963.  
  964. Subject: [74] Introduction to JBIG
  965.  
  966.  
  967. JBIG software and the JBIG specification are available on nic.funet.fi
  968. in /pub/graphics/misc/test-images/jbig.tar.gz.
  969.  
  970.  
  971. A short introduction to JBIG, written by Mark Adler <madler@cco.caltech.edu>:
  972.  
  973.   JBIG losslessly compresses binary (one-bit/pixel) images.  (The B stands
  974.   for bi-level.)  Basically it models the redundancy in the image as the
  975.   correlations of the pixel currently being coded with a set of nearby
  976.   pixels called the template.  An example template might be the two
  977.   pixels preceding this one on the same line, and the five pixels centered
  978.   above this pixel on the previous line.  Note that this choice only
  979.   involves pixels that have already been seen from a scanner.
  980.  
  981.   The current pixel is then arithmetically coded based on the eight-bit
  982.   (including the pixel being coded) state so formed.  So there are (in this
  983.   case) 256 contexts to be coded.  The arithmetic coder and probability
  984.   estimator for the contexts are actually IBM's (patented) Q-coder.  The
  985.   Q-coder uses low precision, rapidly adaptable (those two are related)
  986.   probability estimation combined with a multiply-less arithmetic coder.
  987.   The probability estimation is intimately tied to the interval calculations
  988.   necessary for the arithmetic coding.
  989.  
  990.   JBIG actually goes beyond this and has adaptive templates, and probably
  991.   some other bells and whistles I don't know about.  You can find a
  992.   description of the Q-coder as well as the ancestor of JBIG in the Nov 88
  993.   issue of the IBM Journal of Research and Development.  This is a very
  994.   complete and well written set of five articles that describe the Q-coder
  995.   and a bi-level image coder that uses the Q-coder.
  996.  
  997.   You can use JBIG on grey-scale or even color images by simply applying
  998.   the algorithm one bit-plane at a time.  You would want to recode the
  999.   grey or color levels first though, so that adjacent levels differ in
  1000.   only one bit (called Gray-coding).  I hear that this works well up to
  1001.   about six bits per pixel, beyond which JPEG's lossless mode works better.
  1002.   You need to use the Q-coder with JPEG also to get this performance.
  1003.  
  1004.   Actually no lossless mode works well beyond six bits per pixel, since
  1005.   those low bits tend to be noise, which doesn't compress at all.
  1006.  
  1007.   Anyway, the intent of JBIG is to replace the current, less effective
  1008.   group 3 and 4 fax algorithms.
  1009.  
  1010.  
  1011. Another introduction to JBIG, written by Hank van Bekkem <jbek@oce.nl>:
  1012.  
  1013.   The following description of the JBIG algorithm is derived from
  1014.   experiences with a software implementation I wrote following the
  1015.   specifications in the revision 4.1 draft of September 16, 1991. The
  1016.   source will not be made available in the public domain, as parts of
  1017.   JBIG are patented.
  1018.  
  1019.   JBIG (Joint Bi-level Image Experts Group) is an experts group of ISO,
  1020.   IEC and CCITT (JTC1/SC2/WG9 and SGVIII). Its job is to define a
  1021.   compression standard for lossless image coding ([1]). The main
  1022.   characteristics of the proposed algorithm are:
  1023.   - Compatible progressive/sequential coding. This means that a
  1024.     progressively coded image can be decoded sequentially, and the
  1025.     other way around.
  1026.   - JBIG will be a lossless image compression standard: all bits in
  1027.     your images before and after compression and decompression will be
  1028.     exactly the same.
  1029.  
  1030.   In the rest of this text I will first describe the JBIG algorithm in
  1031.   a short abstract of the draft. I will conclude by saying something
  1032.   about the value of JBIG.
  1033.  
  1034.  
  1035.   JBIG algorithm.
  1036.   --------------
  1037.  
  1038.   JBIG parameter P specifies the number of bits per pixel in the image.
  1039.   Its allowable range is 1 through 255, but starting at P=8 or so,
  1040.   compression will be more efficient using other algorithms. On the
  1041.   other hand, medical images such as chest X-rays are often stored with
  1042.   12 bits per pixel, while no distorsion is allowed, so JBIG can
  1043.   certainly be of use in this area. To limit the number of bit changes
  1044.   between adjacent decimal values (e.g. 127 and 128), it is wise to use
  1045.   Gray coding before compressing multi-level images with JBIG. JBIG
  1046.   then compresses the image on a bitplane basis, so the rest of this
  1047.   text assumes bi-level pixels.
  1048.  
  1049.   Progressive coding is a way to send an image gradually to a receiver
  1050.   instead of all at once. During sending, more detail is sent, and the
  1051.   receiver can build the image from low to high detail. JBIG uses
  1052.   discrete steps of detail by successively doubling the resolution. The
  1053.   sender computes a number of resolution layers D, and transmits these
  1054.   starting at the lowest resolution Dl. Resolution reduction uses
  1055.   pixels in the high resolution layer and some already computed low
  1056.   resolution pixels as an index into a lookup table. The contents of
  1057.   this table can be specified by the user.
  1058.  
  1059.   Compatibility between progressive and sequential coding is achieved
  1060.   by dividing an image into stripes. Each stripe is a horizontal bar
  1061.   with a user definable height. Each stripe is separately coded and
  1062.   transmitted, and the user can define in which order stripes,
  1063.   resolutions and bitplanes (if P>1) are intermixed in the coded data.
  1064.   A progressive coded image can be decoded sequentially by decoding
  1065.   each stripe, beginning by the one at the top of the image, to its
  1066.   full resolution, and then proceeding to the next stripe. Progressive
  1067.   decoding can be done by decoding only a specific resolution layer
  1068.   from all stripes.
  1069.  
  1070.   After dividing an image into bitplanes, resolution layers and
  1071.   stripes, eventually a number of small bi-level bitmaps are left to
  1072.   compress. Compression is done using a Q-coder. Reference [2]
  1073.   contains a full description, I will only outline the basic principles
  1074.   here.
  1075.  
  1076.   The Q-coder codes bi-level pixels as symbols using the probability of
  1077.   occurrence of these symbols in a certain context. JBIG defines two
  1078.   kinds of context, one for the lowest resolution layer (the base
  1079.   layer), and one for all other layers (differential layers).
  1080.   Differential layer contexts contain pixels in the layer to be coded,
  1081.   and in the corresponding lower resolution layer.
  1082.  
  1083.   For each combination of pixel values in a context, the probability
  1084.   distribution of black and white pixels can be different. In an all
  1085.   white context, the probability of coding a white pixel will be much
  1086.   greater than that of coding a black pixel. The Q-coder assigns, just
  1087.   like a Huffman coder, more bits to less probable symbols, and so
  1088.   achieves compression. The Q-coder can, unlike a Huffmann coder,
  1089.   assign one output codebit to more than one input symbol, and thus is
  1090.   able to compress bi-level pixels without explicit clustering, as
  1091.   would be necessary using a Huffman coder.
  1092.  
  1093.   Maximum compression will be achieved when all probabilities (one set
  1094.   for each combination of pixel values in the context) follow the
  1095.   probabilities of the pixels. The Q-coder therefore continuously
  1096.   adapts these probabilities to the symbols it sees.
  1097.  
  1098.  
  1099.   JBIG value.
  1100.   ----------
  1101.  
  1102.   In my opinion, JBIG can be regarded as two combined devices:
  1103.   - Providing the user the service of sending or storing multiple
  1104.     representations of images at different resolutions without any
  1105.     extra cost in storage. Differential layer contexts contain pixels
  1106.     in two resolution layers, and so enable the Q-coder to effectively
  1107.     code the difference in information between the two layers, instead
  1108.     of the information contained in every layer. This means that,
  1109.     within a margin of approximately 5%, the number of resolution
  1110.     layers doesn't effect the compression ratio.
  1111.   - Providing the user a very efficient compression algorithm, mainly
  1112.     for use with bi-level images. Compared to CCITT Group 4, JBIG is
  1113.     approximately 10% to 50% better on text and line art, and even
  1114.     better on halftones. JBIG is however, just like Group 4, somewhat
  1115.     sensitive to noise in images. This means that the compression ratio
  1116.     decreases when the amount of noise in your images increases.
  1117.  
  1118.   An example of an application would be browsing through an image
  1119.   database, e.g. an EDMS (engineering document management system).
  1120.   Large A0 size drawings at 300 dpi or so would be stored using five
  1121.   resolution layers. The lowest resolution layer would fit on a
  1122.   computer screen. Base layer compressed data would be stored at the
  1123.   beginning of the compressed file, thus making browsing through large
  1124.   numbers of compressed drawings possible by reading and decompressing
  1125.   just the first small part of all files. When the user stops browsing,
  1126.   the system could automatically start decompressing all remaining
  1127.   detail for printing at high resolution.
  1128.  
  1129.   [1] "Progressive Bi-level Image Compression, Revision 4.1", ISO/IEC
  1130.       JTC1/SC2/WG9, CD 11544, September 16, 1991
  1131.   [2] "An overview of the basic principles of the Q-coder adaptive
  1132.       binary arithmetic coder", W.B. Pennebaker, J.L. Mitchell, G.G.
  1133.       Langdon, R.B. Arps, IBM Journal of research and development,
  1134.       Vol.32, No.6, November 1988, pp. 771-726 (See also the other
  1135.       articles about the Q-coder in this issue)
  1136.  
  1137. ------------------------------------------------------------------------------
  1138.  
  1139. Subject: [75] Introduction to JPEG
  1140.  
  1141. Here is a brief overview of the inner workings of JPEG, plus some
  1142. references for more detailed information, written by Tom Lane
  1143. <tgl+@cs.cmu.edu>.  Please read item 19 in part 1 first.
  1144.  
  1145. JPEG works on either full-color or gray-scale images; it does not handle
  1146. bilevel (black and white) images, at least not efficiently.  It doesn't
  1147. handle colormapped images either; you have to pre-expand those into an
  1148. unmapped full-color representation.  JPEG works best on "continuous tone"
  1149. images; images with many sudden jumps in color values will not compress well.
  1150.  
  1151. There are a lot of parameters to the JPEG compression process.  By adjusting
  1152. the parameters, you can trade off compressed image size against reconstructed
  1153. image quality over a *very* wide range.  You can get image quality ranging
  1154. from op-art (at 100x smaller than the original 24-bit image) to quite
  1155. indistinguishable from the source (at about 3x smaller).  Usually the
  1156. threshold of visible difference from the source image is somewhere around 10x
  1157. to 20x smaller than the original, ie, 1 to 2 bits per pixel for color images.
  1158. Grayscale requires a little bit less space.
  1159.  
  1160. JPEG defines a "baseline" lossy algorithm, plus optional extensions for
  1161. progressive and hierarchical coding.  There is also a separate lossless
  1162. compression mode; this typically gives about 2:1 compression, ie about 12
  1163. bits per color pixel.  Most currently available JPEG hardware and software
  1164. handles only the baseline mode.
  1165.  
  1166.  
  1167. Here's the outline of the baseline compression algorithm:
  1168.  
  1169. 1. Transform the image into a suitable color space.  This is a no-op for
  1170. grayscale, but for color images you generally want to transform RGB into a
  1171. luminance/chrominance color space (YCbCr, YUV, etc).  The luminance component
  1172. is grayscale and the other two axes are color information.  The reason for
  1173. doing this is that you can afford to lose a lot more information in the
  1174. chrominance components than you can in the luminance component; the human eye
  1175. is not as sensitive to high-frequency color info as it is to high-frequency
  1176. luminance.  (See any TV system for precedents.)  You don't have to change the
  1177. color space if you don't want to, as the remainder of the algorithm works on
  1178. each color component independently, and doesn't care just what the data is.
  1179. However, compression will be less since you will have to code all the
  1180. components at luminance quality.
  1181.  
  1182. 2. (Optional) Downsample each component by averaging together groups of
  1183. pixels.  The luminance component is left at full resolution, while the color
  1184. components are usually reduced 2:1 horizontally and either 2:1 or 1:1 (no
  1185. change) vertically.  In JPEG-speak these alternatives are usually called
  1186. 2h2v and 2h1v sampling, but you may also see the terms "411" and "422"
  1187. sampling.  This step immediately reduces the data volume by one-half or
  1188. one-third, while having almost no impact on perceived quality.  (Obviously
  1189. this would not be true if you tried it in RGB color space...)  Note that
  1190. downsampling is not applicable to gray-scale data.
  1191.  
  1192. 3. Group the pixel values for each component into 8x8 blocks.  Transform each
  1193. 8x8 block through a discrete cosine transform (DCT); this is a relative of the
  1194. Fourier transform and likewise gives a frequency map, with 8x8 components.
  1195. Thus you now have numbers representing the average value in each block and
  1196. successively higher-frequency changes within the block.  The motivation for
  1197. doing this is that you can now throw away high-frequency information without
  1198. affecting low-frequency information.  (The DCT transform itself is reversible
  1199. except for roundoff error.)  See question 25 for fast DCT algorithms.
  1200.  
  1201. 4. In each block, divide each of the 64 frequency components by a separate
  1202. "quantization coefficient", and round the results to integers.  This is the
  1203. fundamental information-losing step.  A Q.C. of 1 loses no information;
  1204. larger Q.C.s lose successively more info.  The higher frequencies are normally
  1205. reduced much more than the lower.  (All 64 Q.C.s are parameters to the
  1206. compression process; tuning them for best results is a black art.  It seems
  1207. likely that the best values are yet to be discovered.  Most existing coders
  1208. use simple multiples of the example tables given in the JPEG standard.)
  1209.  
  1210. 5. Encode the reduced coefficients using either Huffman or arithmetic coding.
  1211. (Strictly speaking, baseline JPEG only allows Huffman coding; arithmetic
  1212. coding is an optional extension.)   Notice that this step is lossless, so it
  1213. doesn't affect image quality.  The arithmetic coding option uses Q-coding;
  1214. it is identical to the coder used in JBIG (see question 74).  Be aware that
  1215. Q-coding is patented.  Most existing implementations support only the Huffman
  1216. mode, so as to avoid license fees.  The arithmetic mode offers maybe 5 or 10%
  1217. better compression, which isn't enough to justify paying fees.
  1218.  
  1219. 6. Tack on appropriate headers, etc, and output the result.  In an
  1220. "interchange" JPEG file, all of the compression parameters are included
  1221. in the headers so that the decompressor can reverse the process.  For
  1222. specialized applications, the spec permits the parameters to be omitted
  1223. from the file; this saves several hundred bytes of overhead, but it means
  1224. that the decompressor must know what parameters the compressor used.
  1225.  
  1226.  
  1227. The decompression algorithm reverses this process, and typically adds some
  1228. smoothing steps to reduce pixel-to-pixel discontinuities.
  1229.  
  1230.  
  1231. Extensions:
  1232.  
  1233. The progressive mode is intended to support real-time transmission of images.
  1234. It allows the DCT coefficients to be sent incrementally in multiple "scans"
  1235. of the image.  With each scan, the decoder can produce a higher-quality
  1236. rendition of the image.  Thus a low-quality preview can be sent very quickly,
  1237. then refined as time allows.  Notice that the decoder must do essentially a
  1238. full JPEG decode cycle for each scan, so this scheme is useful only with fast
  1239. decoders (meaning dedicated hardware, at least at present).  However, the
  1240. total number of bits sent can actually be somewhat less than is necessary in
  1241. the baseline mode, especially if arithmetic coding is used.  So progressive
  1242. coding might be useful even if the decoder will simply save up the bits and
  1243. make only one output pass.
  1244.  
  1245. The hierarchical mode represents an image at multiple resolutions.  For
  1246. example, one could provide 512x512, 1024x1024, and 2048x2048 versions of the
  1247. image.  The higher-resolution images are coded as differences from the next
  1248. smaller image, and thus require many fewer bits than they would if stored
  1249. independently.  (However, the total number of bits will be greater than that
  1250. needed to store just the highest-resolution frame.)  Note that the individual
  1251. frames in a hierarchical sequence may be coded progressively if desired.
  1252.  
  1253.  
  1254. Lossless JPEG:
  1255.  
  1256. The separate lossless mode does not use DCT, since roundoff errors prevent a
  1257. DCT calculation from being lossless.  For the same reason, one would not
  1258. normally use colorspace conversion or downsampling, although these are
  1259. permitted by the standard.  The lossless mode simply codes the difference
  1260. between each pixel and the "predicted" value for the pixel.  The predicted
  1261. value is a simple function of the already-transmitted pixels just above and
  1262. to the left of the current one (eg, their average; 8 different predictor
  1263. functions are permitted).  The sequence of differences is encoded using the
  1264. same back end (Huffman or arithmetic) used in the lossy mode.
  1265.  
  1266. The main reason for providing a lossless option is that it makes a good
  1267. adjunct to the hierarchical mode: the final scan in a hierarchical sequence
  1268. can be a lossless coding of the remaining differences, to achieve overall
  1269. losslessness.  This isn't quite as useful as it may at first appear, because
  1270. exact losslessness is not guaranteed unless the encoder and decoder have
  1271. identical IDCT implementations (ie identical roundoff errors).
  1272.  
  1273.  
  1274. References:
  1275.  
  1276. For a good technical introduction to JPEG, see:
  1277.     Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
  1278.     Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
  1279. (Adjacent articles in that issue discuss MPEG motion picture compression,
  1280. applications of JPEG, and related topics.)  If you don't have the CACM issue
  1281. handy, a PostScript file containing a revised version of this article is
  1282. available at ftp.uu.net, graphics/jpeg/wallace.ps.Z.  The file (actually a
  1283. preprint for an article to appear in IEEE Trans. Consum. Elect.) omits the
  1284. sample images that appeared in CACM, but it includes corrections and some
  1285. added material.  Note: the Wallace article is copyright ACM and IEEE, and
  1286. it may not be used for commercial purposes.
  1287.  
  1288. An alternative, more leisurely explanation of JPEG can be found in "The Data
  1289. Compression Book" by Mark Nelson ([Nel 1991], see question 7).  This book
  1290. provides excellent introductions to many data compression methods including
  1291. JPEG, plus sample source code in C.  The JPEG-related source code is far from
  1292. industrial-strength, but it's a pretty good learning tool.
  1293.  
  1294. An excellent textbook about JPEG is "JPEG Still Image Data Compression
  1295. Standard" by William B. Pennebaker and Joan L. Mitchell.  Published by Van
  1296. Nostrand Reinhold, 1993, ISBN 0-442-01272-1.  650 pages, price US$59.95.
  1297. (VNR will accept credit card orders at 800/842-3636, or get your local
  1298. bookstore to order it.)  This book includes the complete text of the ISO
  1299. JPEG standards, DIS 10918-1 and draft DIS 10918-2.  Review by Tom Lane:
  1300. "This is by far the most complete exposition of JPEG in existence.  It's
  1301. written by two people who know what they are talking about: both serve on the
  1302. ISO JPEG standards committee.  If you want to know how JPEG works or why it
  1303. works that way, this is the book to have."
  1304.  
  1305. There are a number of errors in the first printing of the Pennebaker
  1306. & Mitchell book.  An errata list is available at ftp.uu.net:
  1307. graphics/jpeg/pm.errata.  At last report, all were fixed in the
  1308. second printing.
  1309.  
  1310. The official specification of JPEG is not currently available on-line.
  1311. I hear that CCITT specs may be on-line sometime soon, which would change this.
  1312. At the moment, your best bet is to buy the Pennebaker and Mitchell textbook.
  1313.  
  1314.  
  1315. ------------------------------------------------------------------------------
  1316.  
  1317. Subject: [76] What is Vector Quantization?
  1318.  
  1319. Some vector quantization software for data analysis that is available
  1320. from cochlea.hut.fi (130.233.168.48) in the /pub directory.  One
  1321. package is lvq_pak and one is som_pak (som_pak generates Kohonen maps
  1322. of data using lvq to cluster it).
  1323.  
  1324. For a book on Vector Quantization, see the reference (Gersho and Gray)
  1325. given in item 7 of this FAQ.
  1326.  
  1327. A short introduction to Vector Quantization, written by Alex Zatsman
  1328. <alex.zatsman@analog.com>:
  1329.  
  1330. In Scalar  Quantization one represents  the values by  fixed subset of
  1331. representative values. For  examples, if you  have  16 bit  values and
  1332. send  only 8 most  signifcant bits, you  get an  approximation  of the
  1333. original data  at  the expense of  precision.  In this case  the fixed
  1334. subset is all the 16-bit numbers divisable by 256, i.e 0, 256, 512,...
  1335.  
  1336. In  Vector Quantization  you   represent   not individual values   but
  1337. (usually small) arrays of them. A typical  example  is a color  map: a
  1338. color picture can  be  represented by  a  2D array  of  triplets  (RGB
  1339. values). In most pictures  those triplets do  not cover the  whole RGB
  1340. space but  tend to   concetrate  in certain   areas. For  example, the
  1341. picture of a forest will typically have a lot of green. One can select
  1342. a relatively  small  subset (typically 256 elements) of representative
  1343. colors, i.e RGB  triplets,  and then approximate  each  triplet by the
  1344. representative of  that small set. In case  of 256 one  can use 1 byte
  1345. instead of 3 for each pixel.
  1346.  
  1347. One  can do   the  same   for  any large  data  sets,  especialy  when
  1348. consecutive points are correlated in some way. CELP speech compression
  1349. algorithms  use  those subsets  "codebooks" and   use them to quantize
  1350. exciation vectors  for linear prediction  -- hence the name CELP which
  1351. stands for Codebook Excited Linear Prediction.  (See item 26 in part 1
  1352. of this FAQ for more information about CELP.)
  1353.  
  1354. Note that Vector Quantization, just like Scalar Quantization, is a lossy
  1355. compression.
  1356.  
  1357. ------------------------------------------------------------------------------
  1358.  
  1359. Subject: [77] Introduction to Fractal compression (long)
  1360.  
  1361.  
  1362. Written by John Kominek <jmkomine@jeeves.uwaterloo.ca>.
  1363.  
  1364. Seven things you should know about Fractal Image Compression (assuming that 
  1365. you want to know about it).
  1366.  
  1367.    1. It is a promising new technology, arguably superior to JPEG -- 
  1368.       but only with an argument.
  1369.    2. It is a lossy compression method.
  1370.    3. The fractals in Fractal Image Compression are Iterated Function
  1371.       Systems.
  1372.    4. It is a form of Vector Quantization, one that employs a virtual
  1373.       codebook.
  1374.    5. Resolution enhancement is a powerful feature but is not some
  1375.       magical way of achieving 1000:1 compression.
  1376.    6. Compression is slow, decompression is fast.
  1377.    7. The technology is patented.
  1378.  
  1379. That's the scoop in condensed form. Now to elaborate, beginning with a little 
  1380. background.
  1381.  
  1382.  
  1383.  A Brief History of Fractal Image Compression
  1384.  --------------------------------------------
  1385.  
  1386. The birth of fractal geometry (or rebirth, rather) is usually traced to IBM 
  1387. mathematician Benoit B. Mandelbrot and the 1977 publication of his seminal 
  1388. book The Fractal Geometry of Nature. The book put forth a powerful thesis: 
  1389. traditional geometry with its straight lines and smooth surfaces does not 
  1390. resemble the geometry of trees and clouds and mountains. Fractal geometry, 
  1391. with its convoluted coastlines and detail ad infinitum, does.
  1392.  
  1393. This insight opened vast possibilities. Computer scientists, for one, found a 
  1394. mathematics capable of generating artificial and yet realistic looking land-
  1395. scapes, and the trees that sprout from the soil. And mathematicians had at 
  1396. their disposal a new world of geometric entities.
  1397.  
  1398. It was not long before mathematicians asked if there was a unity among this 
  1399. diversity. There is, as John Hutchinson demonstrated in 1981, it is the branch 
  1400. of mathematics now known as Iterated Function Theory. Later in the decade 
  1401. Michael Barnsley, a leading researcher from Georgia Tech, wrote the popular 
  1402. book Fractals Everywhere. The book presents the mathematics of Iterated Func-
  1403. tions Systems (IFS), and proves a result known as the Collage Theorem. The 
  1404. Collage Theorem states what an Iterated Function System must be like in order 
  1405. to represent an image.
  1406.  
  1407. This presented an intriguing possibility. If, in the forward direction, frac-
  1408. tal mathematics is good for generating natural looking images, then, in the 
  1409. reverse direction, could it not serve to compress images? Going from a given 
  1410. image to an Iterated Function System that can generate the original (or at 
  1411. least closely resemble it), is known as the inverse problem. This problem 
  1412. remains unsolved.
  1413.  
  1414. Barnsley, however, armed with his Collage Theorem, thought he had it solved. 
  1415. He applied for and was granted a software patent and left academia to found 
  1416. Iterated Systems Incorporated (US patent 4,941,193. Alan Sloan is the co-
  1417. grantee of the patent and co-founder of Iterated Systems.)  Barnsley announced 
  1418. his success to the world in the January 1988 issue of BYTE magazine. This 
  1419. article did not address the inverse problem but it did exhibit several images 
  1420. purportedly compressed in excess of 10,000:1. Alas, it was not a breakthrough. 
  1421. The images were given suggestive names such as "Black Forest" and "Monterey 
  1422. Coast" and "Bolivian Girl" but they were all manually constructed. Barnsley's 
  1423. patent has come to be derisively referred to as the "graduate student algo-
  1424. rithm."
  1425.  
  1426. Graduate Student Algorithm
  1427.    o Acquire a graduate student.
  1428.    o Give the student a picture.
  1429.    o And a room with a graphics workstation.
  1430.    o Lock the door.
  1431.    o Wait until the student has reverse engineered the picture.
  1432.    o Open the door.
  1433.  
  1434. Attempts to automate this process have met little success. As Barnsley admit-
  1435. ted in 1988: "Complex color images require about 100 hours each to encode and 
  1436. 30 minutes to decode on the Masscomp [dual processor workstation]." That's 100 
  1437. hours with a _person_ guiding the process.
  1438.  
  1439. Ironically, it was one of Barnsley's PhD students that made the graduate 
  1440. student algorithm obsolete. In March 1988, according to Barnsley, he arrived 
  1441. at a modified scheme for representing images called Partitioned Iterated 
  1442. Function Systems (PIFS). Barnsley applied for and was granted a second patent 
  1443. on an algorithm that can automatically convert an image into a Partitioned 
  1444. Iterated Function System, compressing the image in the process. (US patent 
  1445. 5,065,447. Granted on Nov. 12 1991.) For his PhD thesis, Arnaud Jacquin imple-
  1446. mented the algorithm in software, a description of which appears in his land-
  1447. mark paper "Image Coding Based on a Fractal Theory of Iterated Contractive 
  1448. Image Transformations." The algorithm was not sophisticated, and not speedy, 
  1449. but it was fully automatic. This came at price: gone was the promise of 
  1450. 10,000:1 compression. A 24-bit color image could typically be compressed from 
  1451. 8:1 to 50:1 while still looking "pretty good." Nonetheless, all contemporary 
  1452. fractal image compression programs are based upon Jacquin's paper.
  1453.  
  1454. That is not to say there are many fractal compression programs available. 
  1455. There are not. Iterated Systems sell the only commercial compressor/decompres-
  1456. sor, an MS-Windows program called "Images Incorporated." There are also an 
  1457. increasing number of academic programs being made freely available. Unfor-
  1458. tunately, these programs are -- how should I put it? -- of merely academic 
  1459. quality. 
  1460.  
  1461. This scarcity has much to do with Iterated Systems' tight lipped policy about 
  1462. their compression technology. They do, however, sell a Windows DLL for pro-
  1463. grammers. In conjunction with independent development by researchers else-
  1464. where, therefore, fractal compression will gradually become more pervasive. 
  1465. Whether it becomes all-pervasive remains to be seen.
  1466.  
  1467. Historical Highlights:
  1468.    1977 -- Benoit Mandelbrot finishes the first edition of The Fractal 
  1469.            Geometry of Nature.
  1470.    1981 -- John Hutchinson publishes "Fractals and Self-Similarity."
  1471.    1983 -- Revised edition of The Fractal Geometry of Nature is 
  1472.            published.
  1473.    1985 -- Michael Barnsley and Stephen Demko introduce Iterated
  1474.            Function Theory in "Iterated Function Systems and the Global
  1475.            Construction of Fractals."
  1476.    1987 -- Iterated Systems Incorporated is founded.
  1477.    1988 -- Barnsley publishes the book Fractals Everywhere.
  1478.    1990 -- Barnsley's first patent is granted.
  1479.    1991 -- Barnsley's second patent is granted.
  1480.    1992 -- Arnaud Jacquin publishes an article that describes the first
  1481.            practical fractal image compression method.
  1482.    1993 -- The book Fractal Image Compression by Michael Barnsley and Lyman 
  1483.            Hurd is published.
  1484.         -- The Iterated Systems' product line matures. 
  1485.    1994 -- Put your name here.
  1486.  
  1487.  
  1488.  On the Inside
  1489.  -------------
  1490.  
  1491. The fractals that lurk within fractal image compression are not those of the 
  1492. complex plane (Mandelbrot Set, Julia sets), but of Iterated Function Theory. 
  1493. When lecturing to lay audiences, the mathematician Heinz-Otto Peitgen intro-
  1494. duces the notion of Iterated Function Systems with the alluring metaphor of a 
  1495. Multiple Reduction Copying Machine. A MRCM is imagined to be a regular copying 
  1496. machine except that:
  1497.  
  1498.   1. There are multiple lens arrangements to create multiple overlapping
  1499.      copies of the original.
  1500.   2. Each lens arrangement reduces the size of the original.
  1501.   3. The copier operates in a feedback loop, with the output of one
  1502.      stage the input to the next. The initial input may be anything.
  1503.  
  1504. The first point is what makes an IFS a system. The third is what makes it 
  1505. iterative. As for the second, it is implicitly understood that the functions 
  1506. of an Iterated Function Systems are contractive. 
  1507.  
  1508. An IFS, then, is a set of contractive transformations that map from a defined 
  1509. rectangle of the real plane to smaller portions of that rectangle. Almost 
  1510. invariably, affine transformations are used. Affine transformations act to 
  1511. translate, scale, shear, and rotate points in the plane. Here is a simple 
  1512. example:
  1513.  
  1514.  
  1515.      |---------------|              |-----|
  1516.      |x              |              |1    |
  1517.      |               |              |     |
  1518.      |               |         |---------------|
  1519.      |               |         |2      |3      |
  1520.      |               |         |       |       |
  1521.      |---------------|         |---------------|  
  1522.  
  1523.          Before                      After
  1524.  
  1525.      Figure 1. IFS for generating Sierpinski's Triangle.
  1526.  
  1527. This IFS contains three component transformations (three separate lens ar-
  1528. rangements in the MRCM metaphor). Each one shrinks the original by a factor of 
  1529. 2, and then translates the result to a new location. It may optionally scale 
  1530. and shift the luminance values of the rectangle, in a manner similar to the 
  1531. contrast and brightness knobs on a TV.
  1532.  
  1533. The amazing property of an IFS is that when the set is evaluated by iteration, 
  1534. (i.e. when the copy machine is run), a unique image emerges. This latent image 
  1535. is called the fixed point or attractor of the IFS. As guaranteed by a result 
  1536. known as the Contraction Theorem, it is completely independent of the initial 
  1537. image. Two famous examples are Sierpinski's Triangle and Barnsley's Fern. 
  1538. Because these IFSs are contractive, self-similar detail is created at every 
  1539. resolution down to the infinitesimal. That is why the images are fractal.
  1540.  
  1541. The promise of using fractals for image encoding rests on two suppositions: 1. 
  1542. many natural scenes possess this detail within detail structure (e.g. clouds), 
  1543. and 2. an IFS can be found that generates a close approximation of a scene 
  1544. using only a few transformations. Barnsley's fern, for example, needs but 
  1545. four. Because only a few numbers are required to describe each transformation, 
  1546. an image can be represented very compactly. Given an image to encode, finding 
  1547. the optimal IFS from all those possible is known as the inverse problem.
  1548.  
  1549. The inverse problem -- as mentioned above -- remains unsolved. Even if it 
  1550. were, it may be to no avail. Everyday scenes are very diverse in subject 
  1551. matter; on whole, they do not obey fractal geometry. Real ferns do not branch 
  1552. down to infinity. They are distorted, discolored, perforated and torn. And the 
  1553. ground on which they grow looks very much different.
  1554.  
  1555. To capture the diversity of real images, then, Partitioned IFSs are employed. 
  1556. In a PIFS, the transformations do not map from the whole image to the parts, 
  1557. but from larger parts to smaller parts. An image may vary qualitatively from 
  1558. one area to the next (e.g. clouds then sky then clouds again). A PIFS relates 
  1559. those areas of the original image that are similar in appearance. Using Jac-
  1560. quin's notation, the big areas are called domain blocks and the small areas 
  1561. are called range blocks. It is necessary that every pixel of the original 
  1562. image belong to (at least) one range block. The pattern of range blocks is 
  1563. called the partitioning of an image.
  1564.  
  1565. Because this system of mappings is still contractive, when iterated it will 
  1566. quickly converge to its latent fixed point image. Constructing a PIFS amounts 
  1567. to pairing each range block to the domain block that it most closely resembles 
  1568. under some to-be-determined affine transformation. Done properly, the PIFS 
  1569. encoding of an image will be much smaller than the original, while still 
  1570. resembling it closely.
  1571.  
  1572. Therefore, a fractal compressed image is an encoding that describes:
  1573.    1. The grid partitioning (the range blocks).
  1574.    2. The affine transforms (one per range block).
  1575.  
  1576. The decompression process begins with a flat gray background. Then the set of 
  1577. transformations is repeatedly applied. After about four iterations the attrac-
  1578. tor stabilizes. The result will not (usually) be an exact replica of the 
  1579. original, but reasonably close.
  1580.  
  1581.  
  1582.  Scalelessnes and Resolution Enhancement
  1583.  ---------------------------------------
  1584.  
  1585. When an image is captured by an acquisition device, such as a camera or scan-
  1586. ner, it acquires a scale determined by the sampling resolution of that device. 
  1587. If software is used to zoom in on the image, beyond a certain point you don't 
  1588. see additional detail, just bigger pixels. 
  1589.  
  1590. A fractal image is different. Because the affine transformations are spatially 
  1591. contractive, detail is created at finer and finer resolutions with each itera-
  1592. tion. In the limit, self-similar detail is created at all levels of resolu-
  1593. tion, down the infinitesimal. Because there is no level that 'bottoms out' 
  1594. fractal images are considered to be scaleless.
  1595.  
  1596. What this means in practice is that as you zoom in on a fractal image, it will 
  1597. still look 'as it should' without the staircase effect of pixel replication. 
  1598. The significance of this is cause of some misconception, so here is the right 
  1599. spot for a public service announcement.
  1600.  
  1601.                         /--- READER BEWARE ---\
  1602.  
  1603. Iterated Systems is fond of the following argument. Take a portrait that is, 
  1604. let us say, a grayscale image 250x250 pixels in size, 1 byte per pixel. You 
  1605. run it through their software and get a 2500 byte file (compression ratio = 
  1606. 25:1). Now zoom in on the person's hair at 4x magnification. What do you see? 
  1607. A texture that still looks like hair. Well then, it's as if you had an image 
  1608. 1000x1000 pixels in size. So your _effective_ compression ratio is 25x16=400.
  1609.  
  1610. But there is a catch. Detail has not been retained, but generated. With a 
  1611. little luck it will look as it should, but don't count on it. Zooming in on a 
  1612. person's face will not reveal the pores. 
  1613.  
  1614. Objectively, what fractal image compression offers is an advanced form of 
  1615. interpolation. This is a useful and attractive property. Useful to graphic 
  1616. artists, for example, or for printing on a high resolution device. But it does 
  1617. not bestow fantastically high compression ratios.
  1618.  
  1619.                         \--- READER BEWARE ---/
  1620.  
  1621. That said, what is resolution enhancement? It is the process of compressing an 
  1622. image, expanding it to a higher resolution, saving it, then discarding the 
  1623. iterated function system. In other words, the compressed fractal image is the 
  1624. means to an end, not the end itself.
  1625.  
  1626.  
  1627.  The Speed Problem
  1628.  -----------------
  1629.  
  1630. The essence of the compression process is the pairing of each range block to a 
  1631. domain block such that the difference between the two, under an affine trans-
  1632. formation, is minimal. This involves a lot of searching. 
  1633.  
  1634. In fact, there is nothing that says the blocks have to be squares or even 
  1635. rectangles. That is just an imposition made to keep the problem tractable. 
  1636.  
  1637. More generally, the method of finding a good PIFS for any given image involves 
  1638. five main issues: 
  1639.    1. Partitioning the image into range blocks. 
  1640.    2. Forming the set of domain blocks. 
  1641.    3. Choosing type of transformations that will be considered. 
  1642.    4. Selecting a distance metric between blocks. 
  1643.    5. Specifying a method for pairing range blocks to domain blocks. 
  1644.  
  1645. Many possibilities exist for each of these. The choices that Jacquin offered 
  1646. in his paper are: 
  1647.    1. A two-level regular square grid with 8x8 pixels for the large
  1648.       range blocks and 4x4 for the small ones. 
  1649.    2. Domain blocks are 16x16 and 8x8 pixels in size with a subsampling 
  1650.       step size of four. The 8 isometric symmetries (four rotations, 
  1651.       four mirror flips) expand the domain pool to a virtual domain 
  1652.       pool eight times larger. 
  1653.    3. The choices in the last point imply a shrinkage by two in each 
  1654.       direction, with a possible rotation or flip, and then a trans-
  1655.       lation in the image plane. 
  1656.    4. Mean squared error is used. 
  1657.    5. The blocks are categorized as of type smooth, midrange, simple
  1658.       edge, and complex edge. For a given range block the respective
  1659.       category is searched for the best match.
  1660.  
  1661. The importance of categorization can be seen by calculating the size of the 
  1662. total domain pool. Suppose the image is partitioned into 4x4 range blocks. A 
  1663. 256x256 image contains a total of (256-8+1)^2  = 62,001 different 8x8 domain 
  1664. blocks. Including the 8 isometric symmetries increases this total to 496,008. 
  1665. There are (256-4+1)^2 = 64,009 4x4 range blocks, which makes for a maximum of 
  1666. 31,748,976,072 possible pairings to test. Even on a fast workstation an ex-
  1667. haustive search is prohibitively slow. You can start the program before de-
  1668. parting work Friday afternoon; Monday morning, it will still be churning away. 
  1669.  
  1670. Increasing the search speed is the main challenge facing fractal image com-
  1671. pression.
  1672.  
  1673.  
  1674.  Similarity to Vector Quantization
  1675.  ---------------------------------
  1676.  
  1677. To the VQ community, a "vector" is a small rectangular block of pixels. The 
  1678. premise of vector quantization is that some patterns occur much more frequent-
  1679. ly than others. So the clever idea is to store only a few of these common 
  1680. patterns in a separate file called the codebook. Some codebook vectors are 
  1681. flat, some are sloping, some contain tight texture, some sharp edges, and so 
  1682. on -- there is a whole corpus on how to construct a codebook. Each codebook 
  1683. entry (each domain block) is assigned an index number. A given image, then, is 
  1684. partitioned into a regular grid array. Each grid element (each range block) is 
  1685. represented by an index into the codebook. Decompressing a VQ file involves 
  1686. assembling an image out of the codebook entries. Brick by brick, so to speak.
  1687.  
  1688. The similarity to fractal image compression is apparent, with some notable 
  1689. differences. 
  1690.    1. In VQ the range blocks and domain blocks are the same size; in an
  1691.       IFS the domain blocks are always larger. 
  1692.    2. In VQ the domain blocks are copied straight; in an IFS each domain 
  1693.       block undergoes a luminance scaling and offset.
  1694.    3. In VQ the codebook is stored apart from the image being coded; in 
  1695.       an IFS the codebook is not explicitly stored. It is comprised of
  1696.       portions of the attractor as it emerges during iteration. For that
  1697.       reason it is called a "virtual codebook." It has no existence
  1698.       independent of the affine transformations that define an IFS.
  1699.    4. In VQ the codebook is shared among many images; in an IFS the 
  1700.       virtual codebook is specific to each image.
  1701.  
  1702. There is a more refined version of VQ called gain-shape vector quantization in 
  1703. which a luminance scaling and offset is also allowed. This makes the similari-
  1704. ty to fractal image compression as close as can be.
  1705.  
  1706.  
  1707.  Compression Ratios
  1708.  ------------------
  1709.  
  1710. Exaggerated claims not withstanding, compression ratios typically range from 
  1711. 4:1 to 100:1. All other things equal, color images can be compressed to a 
  1712. greater extent than grayscale images.
  1713.  
  1714. The size of a fractal image file is largely determined by the number of trans-
  1715. formations of the PIFS. For the sake of simplicity, and for the sake of com-
  1716. parison to JPEG, assume that a 256x256x8 image is partitioned into a regular 
  1717. partitioning of 8x8 blocks. There are 1024 range blocks and thus 1024 trans-
  1718. formations to store. How many bits are required for each?
  1719.  
  1720. In most implementations the domain blocks are twice the size of the range 
  1721. blocks. So the spatial contraction is constant and can be hard coded into the 
  1722. decompression program. What needs to be stored are:
  1723.  
  1724.    x position of domain block        8     6
  1725.    y position of domain block        8     6
  1726.    luminance scaling                 8     5
  1727.    luminance offset                  8     6
  1728.    symmetry indicator                3     3
  1729.                                     --    --
  1730.                                     35    26 bits
  1731.  
  1732. In the first scheme, a byte is allocated to each number except for the symme-
  1733. try indicator. The upper bound on the compression ratio is thus (8x8x8)/35 = 
  1734. 14.63. In the second scheme, domain blocks are restricted to coordinates 
  1735. modulo 4. Plus, experiments have revealed that 5 bits per scale factor and 6 
  1736. bits per offset still give good visual results. So the compression ratio limit 
  1737. is now 19.69. Respectable but not outstanding.
  1738.  
  1739. There are other, more complicated, schemes to reduce the bit rate further. The 
  1740. most common is to use a three or four level quadtree structure for the range 
  1741. partitioning. That way, smooth areas can be represented with large range 
  1742. blocks (high compression), while smaller blocks are used as necessary to 
  1743. capture the details. In addition, entropy coding can be applied as a back-end 
  1744. step to gain an extra 20% or so.
  1745.  
  1746.  
  1747.  Quality: Fractal vs. JPEG
  1748.  -------------------------
  1749.  
  1750. The greatest irony of the coding community is that great pains are taken to 
  1751. precisely measure and quantify the error present in a compressed image, and 
  1752. great effort is expended toward minimizing an error measure that most often is 
  1753. -- let us be gentle -- of dubious value. These measure include signal-to-noise 
  1754. ratio, root mean square error, and mean absolute error. A simple example is 
  1755. systematic shift: add a value of 10 to every pixel. Standard error measures 
  1756. indicate a large distortion, but the image has merely been brightened.
  1757.  
  1758. With respect to those dubious error measures, and at the risk of over-sim-
  1759. plification, the results of tests reveal the following: for low compression 
  1760. ratios JPEG is better, for high compression ratios fractal encoding is better. 
  1761. The crossover point varies but is often around 40:1. This figure bodes well 
  1762. for JPEG since beyond the crossover point images are so severely distorted 
  1763. that they are seldom worth using. 
  1764.  
  1765. Proponents of fractal compression counter that signal-to-noise is not a good 
  1766. error measure and that the distortions present are much more 'natural looking' 
  1767. than the blockiness of JPEG, at both low and high bit rates. This is a valid 
  1768. point but is by no means universally accepted. 
  1769.  
  1770. What the coding community desperately needs is an easy to compute error meas-
  1771. ure that accurately captures subjective impression of human viewers. Until 
  1772. then, your eyes are the best judge.
  1773.  
  1774.  
  1775.  Finding Out More
  1776.  ----------------
  1777.  
  1778.  Please refer to item 17 in part 1 of this FAQ for a list of references,
  1779. available software, and ftp sites.
  1780.  
  1781.  
  1782.           End of part 2 of the comp.compression faq.
  1783.